package com.applet.mallappletbackstage.controller;

import com.applet.mallappletbackstage.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@RestController
@RequestMapping("/utils")
public class UtilsController {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("getCode")
    public R checkCode(String phone) {
        Object o = stringRedisTemplate.opsForValue().get(phone);
        Object orElse = Optional.ofNullable(o).orElse("00000");
        return R.success(orElse.toString());
    }
}
